package com.cy.java.opp;

import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;

class Point{
    private int a;
    private int b;
    public Point(int a, int b){
        this.a=a;
        this.b=b;
    }
    public void setA(int a) {
        this.a = a;
    }

    public void setB(int b) {
        this.b = b;
    }

    public int getA() {
        return a;
    }

    public int getB() {
        return b;
    }

    @Override
    public String toString() {
        return "Point{" +
                "a=" + a +
                ", b=" + b +
                '}';
    }
}
public class ReflectTest {
    public static void main(String[] args) throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException, NoSuchFieldException {
        Class<?> c1=Class.forName("com.cy.java.opp.Point");
        Constructor<?> constructor=c1.getConstructor(int.class,int.class);
        Object o1=constructor.newInstance(10,20);
        System.out.println(o1);
        Field f1=c1.getDeclaredField("a");
        f1.setAccessible(true);
        f1.set(o1,1000);
        System.out.println(o1);
    }
}
